<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class BuyerRecordationAndTransferTaxFactory{

    public function createSplitRecordationAndTransferTaxes($propertyTransferTax, $countyPropertyTransferTax, $recordationTax,
                                                                                $extraBuyerRecordationTax,
                                                                                $fees,
                                                                                $payerSpecialCase) {

        //echo ($extraBuyerRecordationTax); exit();
        // CT-8 all recording fees will be charged to the buyer unless the user selects "Seller Pays All" then you will show the fees on the seller's side.
        // To put this another way, the default will always be that the recording fees will be to shown on the buyer's side.

        $zeroRecordationTax = null;
        if ($recordationTax != null) {
            $zeroRecordationTax = new RecordationTax($recordationTax->getName(), 0.0);
        } else {
            $zeroRecordationTax = null;
        }
        //print_r($recordationTax); exit();

        $zeroPropertyTransferTax = null;
        if ($propertyTransferTax != null) {
            $zeroPropertyTransferTax = new StatePropertyTransferTax($propertyTransferTax->getName(), 0.0);
        } else {
            $zeroPropertyTransferTax = null;
        }
        //print_r($zeroPropertyTransferTax); exit();
        
        $zeroCountyPropertyTransferTax = null;
        if ($countyPropertyTransferTax != null) {
            $zeroCountyPropertyTransferTax = new CountyPropertyTransferTax($countyPropertyTransferTax->getName(), 0.0);
        } else {
            $zeroCountyPropertyTransferTax = null;
        }
        //print_r($countyPropertyTransferTax); exit();

        $zeroFees = FeeHelper::getCloneWithZeroValue($fees);

        $recordationAndTransferTaxes = array();

        $buyerRecordationTax = null;
        if ($recordationTax != null) {
            $buyerRecordationTax = new RecordationTax($recordationTax->getName(), $recordationTax->getAmount() + $extraBuyerRecordationTax);
        }
        //print_r($buyerRecordationTax); exit();
        
        if ($payerSpecialCase == null) {
            //echo "ok"; exit();
            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $propertyTransferTax, $countyPropertyTransferTax,
                    $buyerRecordationTax,
                    $fees,
                    EPayer::Buyer);

            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $zeroPropertyTransferTax, $zeroCountyPropertyTransferTax, $zeroRecordationTax,
                    $zeroFees,
                    EPayer::Seller);
        } else if ($payerSpecialCase == EPayerSpecialCase::SellerMustPayStateTax) {
            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $zeroPropertyTransferTax, $countyPropertyTransferTax,
                    $buyerRecordationTax,
                    $fees,
                    EPayer::Buyer);

            $recordationAndTransferTaxes[] = new RecordationAndTransferTaxes(
                    $propertyTransferTax, $zeroCountyPropertyTransferTax, $zeroRecordationTax,
                    $zeroFees,
                    EPayer::Seller);
        }
        //print_r($recordationAndTransferTaxes); exit();

        return $recordationAndTransferTaxes;
    }
}
?>
